package com.ruiboyun.liveapp.util.tool;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.ruiboyun.liveapp.R;
import com.ruiboyun.liveapp.base.App;


/**
 * Created by 吴世芊 on 16/3/7.
 */
public class ToasUtil {


    public static void showToastWithShortTime(Context context, String msg){
        showToast(context, msg, Toast.LENGTH_SHORT);
    }

    public static void showToastWithLongTime(Context context, String msg){
        showToast(context, msg, Toast.LENGTH_LONG);
    }

    public static void showToast(Context context, String msg, int time){
        Toast.makeText(context, msg , time).show();
    }
    public static void showToast(Context context,String msg){
        Toast toast= Toast.makeText(context,msg,Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER,0,0);
        toast.show();
    }
    public static void showCenterToast(Context context,String msg){
        try {
            View layout = LayoutInflater.from(context).inflate(R.layout.toast_layout,null);
            TextView text = (TextView) layout.findViewById(R.id.tvImageToast);
            text.setText(msg);
            Toast toast = new Toast(context);
            toast.setGravity(Gravity.CENTER,0,0);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.setView(layout);
            toast.show();
        }catch (Exception e){
            Toast.makeText(App.getInstance(),msg,Toast.LENGTH_SHORT).show();
            Loger.e("toast 异常1"+e.toString());
            e.printStackTrace();
        }

    }
    public static void showLongToast(Context context,String msg){
        try {
            View layout = LayoutInflater.from(context).inflate(R.layout.toast_layout,null);
            TextView text = (TextView) layout.findViewById(R.id.tvImageToast);
            text.setText(msg);
            Toast toast = new Toast(context);
            toast.setGravity(Gravity.CENTER,0,0);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.setView(layout);
            toast.show();
        }catch (Exception e){
            Toast.makeText(App.getInstance(),msg,Toast.LENGTH_SHORT).show();
            Loger.e("toast 异常2"+e.toString());
            e.printStackTrace();
        }

    }
    public static void showCenterToast(String msg){
        try {
            View layout = LayoutInflater.from(App.getInstance()).inflate(R.layout.toast_layout,null);
            TextView text = (TextView) layout.findViewById(R.id.tvImageToast);
            text.setText(msg);
            Toast toast = new Toast(App.getInstance());
            toast.setGravity(Gravity.CENTER,0,0);
            toast.setDuration(Toast.LENGTH_SHORT);
            toast.setView(layout);
            toast.show();
        }catch (Exception e){
            Toast.makeText(App.getInstance(),msg,Toast.LENGTH_SHORT).show();
            Loger.e("toast 异常3"+e.toString());
            e.printStackTrace();
        }

    }

}
